package edu.xidian.onlinedocument.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Entity
@Table(name = "doc_editor")
@IdClass(DocumentEditorPK.class)    // 存在多个主键时，需要建一个映射主键变量名的类
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class DocumentEditor implements Serializable {

    @Id
    @Column(name = "doc_id")
    @JsonIgnore
        private Integer docId;

    @Id
    @Column(name = "user_id")
    @JsonIgnore
        private Integer editorId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="doc_id", referencedColumnName = "doc_id", insertable = false, updatable = false)
    @JsonIgnoreProperties({"documentEditor"})
        private DocumentData documentData;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="user_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    @JsonIgnoreProperties({"createDocumentData", "editDocumentData"})       // 防止连接后生成的json文件产生死循环，双向连接必须要
        private UserData editorData;

    @Temporal(TemporalType.TIMESTAMP)   //规定Date类型映射为mysql中的DateTime类型
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")    // 用于将Java后端的Date对象转换为指定格式的Json数据传递给前端，也可以指定前端格式
    @Column(name = "doc_editor_delete_time")
        private Date docEditorDeleteTime;

    @Temporal(TemporalType.TIMESTAMP)   //规定Date类型映射为mysql中的DateTime类型
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")    // 用于将Java后端的Date对象转换为指定格式的Json数据传递给前端，也可以指定前端格式
    @Column(name = "doc_editor_edit_time")
        private Date docEditorEditTime;

    @Column(name = "doc_editor_is_delete")
        private boolean docEditorIsDelete;
}
